<?php
if (!defined('IN_XLP')) {
	exit('Access Denied');
}
$Document = array(
	'pageid'   => 'gamearea-add', //页面标示
	'pagename' => '区服添加', //当前页面名称
	'mycss'	   => array(), //加载的css样式表
	'myjs'	   => array(), //加载的js脚本
	'footerjs' => array('content/fuelux/fuelux', 'content/combodate/moment.min'),
	'head'	   => true, //加载头部文件
);

include getTpl('header', 'public');
?>
<style>
#spec_values{width:672px;margin-right:-100px;}
#spec_values input{float:left;width:25%;margin-bottom:15px}
</style>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
<section id="content">
	<section class="main padder">
		<div class="clearfix">
			<h4><i class="fa fa-edit"></i>区服新增</h4>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<section class="panel">
					<div class="panel-body">
						<form class="form-horizontal" id="specAddForm" method="post" autocomplete="on">
							<div class="form-group">
								<label class="col-sm-1 control-label">所属游戏</label>
								<div class="col-sm-2">
                                    <select id="game_id" name="game_id" class="form-control">
                                        <option value="-1">选择游戏</option>
                                        <?php foreach ($games as $k => $v): ?>
                                        <option value="<?php echo $v['id'] ?>"><?php echo $v['name']." [".$v['abridge']."]" ?></option>
                                        <?php endforeach ?>
                                    </select>
                                </div>
							</div>

							<div class="form-group">
								<label class="col-sm-1 control-label">区信息</label>
								<div class="col-sm-2">
									<input type="text" name="area_name" id="area_name" placeholder="电信区" class="form-control" data-required="true" />
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-1 control-label">服信息</label>
								<div class="col-sm-2" id="spec_values">
									<input type="text" name="server_name[]" placeholder="服名称" class="form-control" value="">
									<input style="margin-left:20px;" type="text" name="abridge[]" placeholder="编码" class="form-control" value="">
									<input style="margin-left:20px;" type="text" name="cross_no[]" placeholder="跨区编码" class="form-control" value="">
								</div>
								<button id="addmore" type="button" class="btn btn-white">添加更多</button>
							</div>

							<div class="form-group">
								<label class="col-sm-1 control-label">排序</label>
								<div class="col-sm-2">
									<input type="text" name="area_sort" placeholder="" class="form-control" value="255">
								</div>
							</div>

							<div class="form-group">
								<div class="col-sm-9 col-lg-offset-1">
									<div class="col-sm-1">
										<button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
									</div>
									<button type="button" class="btn btn-white">取消</button>
								</div>
							</div>

						</form>
					</div>
				</section>
			</div>
		</div>
	</section>
</section>
<!--/ content --> 
<!--主体 结束-->
<script>
$(function(){
	var $sp_val = $('#spec_values');
	var input   = $sp_val.html();
	$('#addmore').click(function(){
		$sp_val.append(input);
	});
	$('#specAddForm').submit(function(){

		if($('#game_id').val() == -1) {
			Msg.error('请选择游戏');
			resetSubmit("#sub-ok",'提交');
			return false;
		}

		if( $.trim($('#area_name').val()) == '' ) {
			Msg.error('请输入区信息');
			resetSubmit("#sub-ok",'提交');
			return false;
		}

		Msg.loading();
		$.post('<?php echo U("gamearea/add"); ?>', $(this).serialize(), function(json){
			Msg.hide();
			resetSubmit("#sub-ok",'提交');
			if(json.err) {
				Msg.error(json.msg);
			} else {
				Msg.ok(json.msg);
				setTimeout(function () {
                    window.location.reload();
              	}, 3000);
			}
		}, 'JSON');
		return false;
	});
});
</script>
<?php include getTpl('footer', 'public'); ?>